﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;



namespace AimGameEngine.NodeEditorObject
{
    partial class PropretyKeyController : Form
    {
        NodeKeyController nodekeycontroller;
        public PropretyKeyController(NodeKeyController nodekeycontroller)
        {
            InitializeComponent();

            this.nodekeycontroller = nodekeycontroller;

            Microsoft.Xna.Framework.Input.Keys getkeys = Microsoft.Xna.Framework.Input.Keys.None;
            foreach (string str in Enum.GetNames(getkeys.GetType()))
                this.comboBoxKey.Items.Add(str);

            this.comboBoxKey.SelectedItem = nodekeycontroller.mykeys.ToString();

            this.comboBoxMode.SelectedItem = nodekeycontroller.InputMode.ToString();
           
        }

        private void okButton_Click(object sender, EventArgs e)
        {
             Microsoft.Xna.Framework.Input.Keys getkeys = Microsoft.Xna.Framework.Input.Keys.None;
             foreach (int i in Enum.GetValues(getkeys.GetType()))
             {
                 string str = Enum.GetName(getkeys.GetType(), i);
                 if (str == (String)comboBoxKey.SelectedItem)
                 {
                     nodekeycontroller.mykeys = (Microsoft.Xna.Framework.Input.Keys)Enum.ToObject(getkeys.GetType(), i);
                     break;
                 }
             }

             String tempString = (String)this.comboBoxMode.SelectedItem;
             if (tempString == AimGameLibrary.NodeInputMode.Pressed_Release.ToString())
             {
                 if (this.nodekeycontroller.InputMode.ToString() != tempString)
                 {
                     this.nodekeycontroller.DictionaryObjectUpdatePressed.Clear();
                     this.nodekeycontroller.DictionaryObjectUpdateRelease.Clear();
                     foreach(String keyIsdownToPressed in nodekeycontroller.DictionaryObjectUpdateIsdown.Keys)
                         this.nodekeycontroller.DictionaryObjectUpdatePressed.Add(keyIsdownToPressed,this.nodekeycontroller.DictionaryObjectUpdateIsdown[keyIsdownToPressed]);
                     foreach (String keyIsupToRelease in nodekeycontroller.DictionaryObjectUpdateIsup.Keys)
                         this.nodekeycontroller.DictionaryObjectUpdateRelease.Add(keyIsupToRelease, this.nodekeycontroller.DictionaryObjectUpdateIsup[keyIsupToRelease]);
                 }
                 this.nodekeycontroller.InputMode = AimGameLibrary.NodeInputMode.Pressed_Release;
             }
             else if (tempString == AimGameLibrary.NodeInputMode.Isdown_Isup.ToString())
             {
                 if (this.nodekeycontroller.InputMode.ToString() != tempString)
                 {
                     this.nodekeycontroller.DictionaryObjectUpdateIsdown.Clear();
                     this.nodekeycontroller.DictionaryObjectUpdateIsup.Clear();
                     foreach (String keyPressedToIsdown in nodekeycontroller.DictionaryObjectUpdatePressed.Keys)
                         this.nodekeycontroller.DictionaryObjectUpdateIsdown.Add(keyPressedToIsdown, this.nodekeycontroller.DictionaryObjectUpdatePressed[keyPressedToIsdown]);
                     foreach (String keyReleaseToIsup in nodekeycontroller.DictionaryObjectUpdateRelease.Keys)
                         this.nodekeycontroller.DictionaryObjectUpdateIsup.Add(keyReleaseToIsup, this.nodekeycontroller.DictionaryObjectUpdateRelease[keyReleaseToIsup]);
                 }
                 this.nodekeycontroller.InputMode = AimGameLibrary.NodeInputMode.Isdown_Isup;
             }

             //nodekeycontroller.SetupProprety();
        }

    }
}
